package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.OrderBean;
import com.project.bean.UserBean;
import com.project.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("custom/order")
public class OrderController {
    @Autowired
    private IOrderService service;
    @RequestMapping("addOrder")
    public  String addOrder(OrderBean order, HttpServletRequest request){
        //得到登录信息
      UserBean loginUser= (UserBean) request.getSession().getAttribute("loginUser");
      //添加订单
        service.add(order,loginUser.getId());
        return  "ok";

    }

    @RequestMapping("findById")
    public OrderBean findById(int id){
        return service.findById(id);
    }

    @RequestMapping("findByUser")
    public IPage<OrderBean> findByUser(HttpServletRequest request, int pageNO){
        UserBean user = (UserBean) request.getSession().getAttribute("loginUser");
        return service.findByUser(user.getId(),pageNO);

    }



}
